namespace Vin.Extension.Win32.Command.Workflow;

public enum VariableType
{
    String, // 字符串
    Dynamic, // 动态
}

public class Variable
{
    /// <summary>
    /// 变量名称
    /// </summary>
    public string Key { get; set; } = null!;

    /// <summary>
    /// 变量类型
    /// </summary>
    public VariableType Type { get; set; }

    /// <summary>
    /// 变量默认值
    /// </summary>
    public object? DefaultValue { get; set; }

    /// <summary>
    /// 变量备注
    /// </summary>
    public string? Remark { get; set; }

    /// <summary>
    /// 动态变量值
    /// </summary>
    public Func<object>? DynamicValue { get; set; }

    /// <summary>
    /// 变量值
    /// </summary>
    public object? Value { get; private set; }

    public object? GetValue()
    {
        if (Type == VariableType.Dynamic && DynamicValue != null)
        {
            Value = DynamicValue?.Invoke();
        }

        if (Value == null && DefaultValue != null)
        {
            Value = DefaultValue;
        }

        return Value;
    }
    
    public bool SetValue(object value)
    {
        Value = value;
        return true;
    }
}